/****************************************************/
 /* Project Name:预约配置信息管理                             */
 /* File Name:TdcTimesController            */
 /* Date:2017年3月22日下午19:59:12            */
 /* Description:预约配置信息的业务逻辑层控制器        */
 /****************************************************/ 
package com.thinkgem.jeesite.modules.tdc.times.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.tdc.times.entity.TdcTimes;
import com.thinkgem.jeesite.modules.tdc.times.service.TdcTimesService;

/**
 * 预约配置Controller
 * @author 孙瑞曦
 * @version 2017-03-27
 */
@Controller
@RequestMapping(value = "${adminPath}/times/tdcTimes")
public class TdcTimesController extends BaseController {

	@Autowired
	private TdcTimesService tdcTimesService;
	
	@ModelAttribute
	public TdcTimes get(@RequestParam(required=false) String id) {
		TdcTimes entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tdcTimesService.get(id);
		}
		if (entity == null){
			entity = new TdcTimes();
		}
		return entity;
	}
	/**
	 * list:(分页管理类页面，获取所有的预约配置信息)
	 * @param tdcTimes：预约配置表的实体类对象
	 * @param request：向服务器提交pagesize和pageNo的信息
	 * @param response：向客户端回应返回来的pagesize和pageno信息
	 * @param model：预约配置表的实体类entity
	 * @return 返回到分类查询页面
	 */
	@RequiresPermissions("times:tdcTimes:view")
	@RequestMapping(value = {"list", ""})
	public String list(TdcTimes tdcTimes, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TdcTimes> page = tdcTimesService.findPage(new Page<TdcTimes>(request, response), tdcTimes); 
		model.addAttribute("page", page);
		return "tdc/times/tdcTimesList";
	}
	/**
	 * form:(预约配置信息录入)
	 * @param tdcTimes：预约配置表的实体类对象
	 * @param model：预约配置表的实体类entity
	 * @return 进入到基础信息录入页
	 */
	@RequiresPermissions("times:tdcTimes:view")
	@RequestMapping(value = "form")
	public String form(TdcTimes tdcTimes, Model model) {
		model.addAttribute("tdcTimes", tdcTimes);
		return "tdc/times/tdcTimesForm";
	}
	/**
	 * save:(保存录入的预约配置信息)
	 * @param tdcTimes：预约配置表的实体类对象
	 * @param model：预约配置表的实体类entity
	 * @param redirectAttributes：保存成功后的提示信息
	 * @return 返回到list方法
	 */
	@RequiresPermissions("times:tdcTimes:edit")
	@RequestMapping(value = "save")
	public String save(TdcTimes tdcTimes, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tdcTimes)){
			return form(tdcTimes, model);
		}
		tdcTimesService.save(tdcTimes);
		addMessage(redirectAttributes, "保存预约配置成功");
		return "redirect:"+Global.getAdminPath()+"/times/tdcTimes/?repage";
	}
	/**
	 * delete:(在预约配置查询页面中，根据id删除预约配置信息)
	 * @param tdcTimes：预约配置表的实体类对象
	 * @param redirectAttributes：删除成功后的提示信息
	 * @return 返回到list方法
	 */
	@RequiresPermissions("times:tdcTimes:edit")
	@RequestMapping(value = "delete")
	public String delete(TdcTimes tdcTimes, RedirectAttributes redirectAttributes) {
		tdcTimesService.delete(tdcTimes);
		addMessage(redirectAttributes, "删除预约配置成功");
		return "redirect:"+Global.getAdminPath()+"/times/tdcTimes/?repage";
	}

}